# -*- coding: utf-8 -*-
import scrapy


class A21foodSpider(scrapy.Spider):
    name = '21food'
    allowed_domains = ['21food.cn']

    def __init__(self, kw=None):
        self.start_urls = [
            'https://www.21food.cn/product/search_keys-{0}.html'.format(kw)]

    def start_requests(self):
        for url in self.start_urls:
            req = scrapy.Request(url, callback=self.parse)
            # referer =
            # if referer:
            #     req.headers["referer"] = referer
            yield req

    def parse(self, response):
        with open('food.html', 'wb') as f:
            f.write(response.body)
